package com.szpx.mapper;

import com.szpx.entity.DdwUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/*
新增账号
 */
public interface DdwUserMapper {
    @Insert("INSERT INTO ddwUser ( email, password, salt, confirm_code, activation_time, is_valid)" +
            "VALUES(#{email} , #{password} , #{salt} , #{confirmCode} , #{activationTime} , #{isValid})")
    int inserUser(DdwUser ddwUser);

    @Select("SELECT email,activation_time FROM ddwUser WHERE confirm_code = #{confirmCode} AND is_valid = 0")
     DdwUser selectUserByConfirmCode(@Param("confirmCode") String confirmCode);

    /*
    根据确认码查询用户修改状态值为1
     */
    @Update("UPDATE ddwUser SET is_valid = 1 WHERE confirm_code = #{confirmCode}")
    int updateUserByConfirmCode(@Param("confirmCode") String confirmCode);
    /*
    根据邮箱查询用户
     */
    @Select("SELECT  email, password, salt FROM ddwUser WHERE email = #{email} AND is_valid = 1")
    List<DdwUser> selectUerByEmail(@Param("email") String email);

}

